package com.kuang.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
//@EnableWebMvc  这个要注解掉  css 加载不到就是这个原因地方没有去掉
public class MyMvcConfig implements WebMvcConfigurer {

    @Override//添加视图控制
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("dashboard");
    }

    //自定义的国际化组件就生效了
    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }

    //配置拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * /**全部的都拦截
         * 其中/，/index.html，/user/login,/css/** ，/js/** ，/single/down/**不拦截
         */
        registry.addInterceptor(new LoginHandlerlnterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/","/index.html","/user/login","/css/**","/js/**","/img/**","/single/down/**",
                        "/assets/**","/manage_device/**","/manage/ImportManageId");   //自己定义的
    }

}


